//给定一个头节点为 head 的链表用于记录一系列核心肌群训练项目编号，请查找并返回倒数第 cnt 个训练项目编号。 
//
// 
//
// 示例 1： 
//
// 
//输入：head = [2,4,7,8], cnt = 1
//输出：8 
//
// 
//
// 提示： 
//
// 
// 1 <= head.length <= 100 
// 0 <= head[i] <= 100 
// 1 <= cnt <= head.length 
// 
//
// 
//
// Related Topics 链表 双指针 👍 530 👎 0


package LeetCode.editor.cn;


/**
 * @author ldltd
 * @date 2025-04-29 16:29:13
 * @description LCR 140.训练计划 II
 
 */
 
public class LianBiaoZhongDaoShuDiKgeJieDianLcof {
    public static void main(String[] args) {
    //测试代码
    LianBiaoZhongDaoShuDiKgeJieDianLcof fun = new LianBiaoZhongDaoShuDiKgeJieDianLcof();
    Solution solution= fun.new Solution();
    
    }

//leetcode submit region begin(Prohibit modification and deletion)

//  Definition for singly-linked list.
  public class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }

class Solution {
    public ListNode trainingPlan(ListNode head, int cnt) {
        ListNode p=new ListNode(-1);
        p.next=head;
        ListNode fast=p,slow=p;
        while (cnt!=0){
            fast=fast.next;
            cnt--;
        }
        while (fast!=null){
            slow=slow.next;
            fast=fast.next;
        }
        return slow;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}
